package de.velvettear.squirrel.database;

public class Column {
	
	public enum ColumnDataType {
		sql_varchar, sql_integer
	}
	
	public String m_sName;
	public int m_nLength;
	public boolean m_bPrimaryKey;
	public ColumnDataType m_cDatatype;
	public boolean m_bNullAble;
	
	public Column() {
		
	}
	
	public Column(String m_sColumnName, int m_nLength, boolean m_bPrimaryKey, ColumnDataType m_cDataTyp) {
		super();
		this.m_sName = m_sColumnName;
		this.m_nLength = m_nLength;
		this.m_bPrimaryKey = m_bPrimaryKey;
		this.m_cDatatype = m_cDataTyp; 
		this.m_bNullAble = false;
	}
	
	
	public Column(String m_sColumnName, int m_nLength, boolean m_bPrimaryKey, ColumnDataType m_cDataTyp, boolean NullAble) {
		super();
		this.m_sName = m_sColumnName;
		this.m_nLength = m_nLength;
		this.m_bPrimaryKey = m_bPrimaryKey;
		this.m_cDatatype = m_cDataTyp;
	}
	
	public String getSqlDefinitionString(){
		String retVal = this.m_sName + " ";
		
		switch (this.m_cDatatype) {
			case sql_varchar :
				retVal +="varchar(" + String.valueOf(this.m_nLength) + ") NOT NULL DEFAULT ''";
			break;
			case sql_integer :
				retVal +="integer";
			break;
		}
		
		if (this.m_bPrimaryKey)
			retVal += " primary key autoincrement";
		
		return retVal;
	}
}
